package bb.lanxing.network;

import bb.lanxing.manager.SharedManager;
import java.io.IOException;
import okhttp3.Interceptor;
import okhttp3.Request;

public class HttpsInterceptor implements Interceptor {
    @Override
    public okhttp3.Response intercept(Interceptor.Chain chain) throws IOException {
        Request request = chain.request();
        if (SharedManager.getInstance().isUseHttps()) {
            if (!chain.request().url().isHttps()) {
                return chain.proceed(request.newBuilder().url(request.url().newBuilder().scheme("https").build()).build());
            }
            return chain.proceed(request);
        } else if (chain.request().url().isHttps()) {
            return chain.proceed(request.newBuilder().url(request.url().newBuilder().scheme("http").build()).build());
        } else {
            return chain.proceed(request);
        }
    }
}
